//主从表tab选项卡标志位
var {$RDA$}_Tab_Flag = -1;
//选择某一行
var {$RDA$}_select_{template_table_EN}_rowId = "";
//按钮事件新增或编辑
var {$RDA$}_type = "";
//其他页面传到本页面参数
var {$RDA$}_param = {};
//本页面传到其他页面参数
var {$RDA$}_toparam = {};
//table选中数据，如无则默认第一条
var {$RDA$}_rowCheckData = null;
//当前触发按钮
var {$RDA$}_btn = "";
//上一次触发的按钮
var {$RDA$}_prev_btn = "";
//树形节点选择
var {$RDA$}_select_TreeNode = {};
//表格数据服务端分页或客户端分页 1:服务端 0:客户端
var {$RDA$}_table_page = 0;

/*定义查询条件变量*/
/*declare query param begin*/

/*declare query param end*/

/*定义下拉框集合定义*/
/*declare select options begin*/

/*declare select options end*/

/*文件附件格式*/
/*input param fileinfo begin*/

/*input param fileinfo end*/

/*绑定show监听事件*/
if({$RDA$}_Tab_Flag == -1){
	var {$RDA$}_n = Get_RandomDiv("{$RDA$}","");
	$({$RDA$}_n).bind("show", function(objTag){
		{$RDA$}_Adjust_Sub_Sequ();
		if(!$({$RDA$}_n).is(":hidden") && {$RDA$}_Tab_Flag > 0 && ("#"+objTag.currentTarget.id.toString()) == {$RDA$}_n)
			{$RDA$}_adjust_tab();		
	});
}

//设置主从表div顺序
function {$RDA$}_Adjust_Sub_Sequ(){
	var temSubDivs = $("#content-main").find("div[data-id]");
	var MainDiv = $(Get_RandomDiv("{$RDA$}",""));
	for(i = 0; i < temSubDivs.length; i++) {
		if({$RDA$}_Is_Sub_Div(temSubDivs[i].id)){
			$(temSubDivs[i]).before($(MainDiv));
			break;
		}
	}
}

//主从表传递参数
function {$RDA$}_param_set(){
	/*Main Subsuv Table Param Begin*/
	
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function {$RDA$}_{template_table_EN}_biz_start(inputparam) {
	layer.close(ly_index);
	{$RDA$}_param = inputparam;
	$('#{$RDA$}_btn_{template_table_EN}_refresh').click();
}

/*业务函数步骤*/
/*biz step begin*/

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function {$RDA$}_page_end(){
	page_btn_priv("{$RDA$}");
	{$RDA$}_adjust_tab();
}

//按钮弹窗
window.{$RDA$}_Upd_EvaEvents = {'click #{$RDA$}_btn_Upd': function (e, value, row, index) {
		{$RDA$}_prev_btn = "";
		{$RDA$}_btn = "{$RDA$}_btn_{template_table_EN}_edit";
		{$RDA$}_select_{template_table_EN}_rowId = index.toString();
		//$("#{$RDA$}_btn_{template_table_EN}_edit").click();//此处不需要执行，在table row行click中执行
	}
	//按钮事件
	/*table button events begin*/
	/*table button events end*/
};

//按钮定义
function {$RDA$}_Upd_EvaFormatter(value, row, index) {
	var btnHtml = "<div style=\"display: block;\">"
	/*table button defined begin*/
	/*table button defined end*/
	btnHtml += "</div>";
	return [btnHtml].join();
}

//{template_table_CN}显示列定义
var {$RDA$}_{template_table_EN} = [
	{ 
		checkbox:true
	},
	/*table column begin*/
	
	/*table column end*/
	,{
        title: '操作',
        class: 'tb_columns',
        events: {$RDA$}_Upd_EvaEvents,
        formatter: {$RDA$}_Upd_EvaFormatter
    }
];

//页面初始化
function {$RDA$}_init_{template_table_EN}() {
	$(window).resize(function () {
		  $('#{$RDA$}_{template_table_EN}_Events').bootstrapTable('resetView');
	});
	//{template_table_CN}查询条件初始化设置
	/*query conditions init begin*/
	
    /*query conditions init end*/
	
	$('#{$RDA$}_btn_{template_table_EN}_query').click();
}

//查询接口
function {$RDA$}_{template_table_EN}_query() {
    $('#{$RDA$}_{template_table_EN}_Events').bootstrapTable("removeAll");
	//以下为特殊字段列表查询，无特殊字段时不需要
	var inputdata = {
		"param_name": "N01_sel_{template_table_EN}_ByNodeID",
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
        /*get query param begin*/
		,"param_value1": {$RDA$}_tem_TreeNode		
        /*get query param end*/
	};
	ly_index = layer.load();
	if({$RDA$}_table_page == 1){
		inputdata = {"N01_sel_{template_table_EN}_ByNodeID":[]};
		{$RDA$}_get_N01_sel_{template_table_EN}_ByNodeID(inputdata);
	}
	else{
		delete inputdata["pageNumber"];
		delete inputdata["pageSize"];
		get_ajax_baseurl(inputdata, "{$RDA$}_get_N01_sel_{template_table_EN}_ByNodeID");
	}
}

//树形结构函数定义
/*tree function defined begin*/
/*tree function defined end*/

//查询结果
function {$RDA$}_get_N01_sel_{template_table_EN}_ByNodeID(input) {
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.N01_sel_{template_table_EN}_ByNodeID) == false)
        return false;
    //树形结构函数调用
    /*tree function run begin*/
    /*tree function run end*/    
    {$RDA$}_rowCheckData = null;
    //调整table各列宽度
    $.each({$RDA$}_{template_table_EN}, function (i, obj) {
		if(obj.title != undefined && (obj.visible == undefined || obj.visible == true)){
			obj.width = obj.title.length * 14 + 37;
		}
		//操作列宽度定义
		if(i == {$RDA$}_{template_table_EN}.length - 1){
			obj.width = "200";
		}
	});

	var s_data = input.N01_sel_{template_table_EN}_ByNodeID;
    {$RDA$}_select_{template_table_EN}_rowId = "";
    if(s_data.length > 0){
    	{$RDA$}_rowCheckData = s_data[0]; 
    }
    //table对应的属性
    var temTableAtt = {};
    if({$RDA$}_table_page == 1){
    	temTableAtt["url"] = bizzUrl;
    	temTableAtt["method"] = "get";
    	temTableAtt["sidePagination"] = "server";
    	temTableAtt["queryParamsType"] = "limit";
    }
    else{
    	temTableAtt["url"] = null;
    	temTableAtt["method"] = null;
    	temTableAtt["sidePagination"] = null;
    	temTableAtt["queryParamsType"] = null;
    }
    $('#{$RDA$}_{template_table_EN}_Events').bootstrapTable('destroy');
    $("#{$RDA$}_{template_table_EN}_Events").bootstrapTable({
        uniqueId: 'main_id',
        search: !0,
        pagination: !0,
        showRefresh: !0,
        showToggle: !0,
        locale: "zh-CN",
        showColumns: !0,
        showExport: !0,
        exportDataType:"all",
        exportTypes:['excel'],
        iconSize: "outline",
        onClickRow: function (row, $element) {
            // 判断是否已选中
            if ({$RDA$}_prev_btn == {$RDA$}_btn && $($element).hasClass("changeColor")) {
                $('#{$RDA$}_{template_table_EN}_Events').find("tr.changeColor").removeClass('changeColor');
                {$RDA$}_select_{template_table_EN}_rowId = "";
            }
            else {
                // 未点击则，为当前行添加 class='changeColor'
                $('#{$RDA$}_{template_table_EN}_Events').find("tr.changeColor").removeClass('changeColor');
                $($element).addClass('changeColor');                　
                {$RDA$}_select_{template_table_EN}_rowId = $element.attr('data-index');
                
                //设置子表查询条件
                /*set child table qry begin*/
                
                $($("#{$RDA$}_TAB_MAIN").find(".active")[0]).click();
                /*set child table qry end*/
                //判断是否button按钮点击事件
        		if(typeof($("#{$RDA$}_TAB_MAIN").find(".active")[0]) == "undefined" && {$RDA$}_prev_btn != {$RDA$}_btn){
        			{$RDA$}_prev_btn = {$RDA$}_btn;
        			if($("#"+{$RDA$}_btn)[0] == undefined)
        				eval({$RDA$}_btn + "()");
        			else
        				$("#"+{$RDA$}_btn).click();
        		}
            }
        },
		onDblClickRow: function (row){
			if({$RDA$}_param.hasOwnProperty("target_name"))
			{
				$("#"+{$RDA$}_param["target_id"]).val(eval("row."+{$RDA$}_param["sourc_id"].toUpperCase()));
				$("#"+{$RDA$}_param["target_name"]).val(s_decode(eval("row."+{$RDA$}_param["sourc_name"].toUpperCase())));				
				layer.close({$RDA$}_param["ly_index"]);
			}
		},
        toolbar: "#{$RDA$}_{template_table_EN}_Toolbar",
        url: temTableAtt["url"],
        method: temTableAtt["method"],
        height:500,
        columns: {$RDA$}_{template_table_EN},
        data: s_data,
        pageNumber: 1,
        pageSize: 10, // 每页的记录行数（*）
        pageList: [10,50,100,1000,2000], // 可供选择的每页的行数（*）
        queryParams: {$RDA$}_{template_table_EN}_queryParams,
        sidePagination: temTableAtt["sidePagination"],//"server", //服务端处理分页
	    queryParamsType : temTableAtt["queryParamsType"],//"limit",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
        icons: {
            refresh: "glyphicon-repeat",
            toggle: "glyphicon-list-alt",
            columns: "glyphicon-list"
        },
        onPostBody:function(){
        },
        onLoadSuccess: function(input){
        	if(input.rows.length > 0)
        		{$RDA$}_rowCheckData = input.rows[0]; 
        },
        onLoadError: function(err){
            console.log("error: "+err);
        },
        responseHandler:{$RDA$}_Res_N01_sel_{template_table_EN}_ByNodeID
    });
    {$RDA$}_page_end();
}

//设置参数
function {$RDA$}_{template_table_EN}_queryParams(inputdata){
	ly_index = layer.load();
	if({$RDA$}_table_page == 0)
		return null;
	var temdata = {
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
		/*get query param begin*/
		/*get query param end*/
	};
	for (var key in temdata) {
		inputdata[key] = temdata[key];
    }
	inputdata["param_name"] = "N01_sel_{template_table_EN}_ByNodeID";
	if(inputdata.hasOwnProperty("offset") && inputdata.hasOwnProperty("limit")){
		inputdata["pageNumber"] = parseInt(inputdata["offset"] / inputdata["limit"]) + 1;
		inputdata["pageSize"] = inputdata["limit"];
	}
	else{
		inputdata["pageNumber"] = 0;
		inputdata["pageSize"] = 0;
	}
	return inputdata;
}

//获取接口数据
function {$RDA$}_Res_N01_sel_{template_table_EN}_ByNodeID(input){
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.N01_sel_{template_table_EN}_ByNodeID) == false)
        return false;
    if(input["N01_sel_{template_table_EN}_ByNodeID"].length > 0)
    	{$RDA$}_rowCheckData = input["N01_sel_{template_table_EN}_ByNodeID"][0];
    if({$RDA$}_table_page == 0)
		return null;
	else{ 
		var json_list = {};
		json_list["total"] = input["N01_sel_{template_table_EN}_ROWS"];
		json_list["rows"] = input["N01_sel_{template_table_EN}_ByNodeID"];
		return json_list;
	}
}

//多选记录返回
$("#{$RDA$}_btn_mult_check").click(function (){	
	//单行选择
	var rowData = $("#{$RDA$}_{template_table_EN}_Events").bootstrapTable('getData')[{$RDA$}_select_{template_table_EN}_rowId];
	//多行选择
	var rowDatas = {$RDA$}_sel_row_{template_table_EN}();
	var temtarget_id = "";
	var temtarget_name = "";
	if(rowDatas.length > 0)
	{
  	$.each(rowDatas, function (i, obj) {
  		if(temtarget_id != ""){
  			temtarget_id += ",";
  			temtarget_name += ",";
  		}
  		temtarget_name += s_decode(obj[{$RDA$}_param["sourc_name"].toUpperCase()]);    		
			temtarget_id += obj[{$RDA$}_param["sourc_id"].toUpperCase()];
  	});
	}
	else if({$RDA$}_select_v_menu_info_rowId != "")
	{
		temtarget_id = rowData[{$RDA$}_param["sourc_id"].toUpperCase()];
		temtarget_name = s_decode(rowData[{$RDA$}_param["sourc_name"].toUpperCase()]); 
	}
	
	if({$RDA$}_param.hasOwnProperty("target_name"))
	{
		$("#"+{$RDA$}_param["target_id"]).val(temtarget_id);
		$("#"+{$RDA$}_param["target_name"]).val(temtarget_name);				
		layer.close({$RDA$}_param["ly_index"]);
	}
});

//刷新按钮
$('#{$RDA$}_btn_{template_table_EN}_refresh').click(function () {
	/*重置查询条件变量*/
	/*refresh query param begin*/

	/*refresh query param end*/

	/*重置下拉框集合定义*/
	/*refresh select options begin*/

	/*refresh select options end*/
	//主从表传递参数
	{$RDA$}_param_set();
	/*页面重置重新加载*/
	/*biz begin*/
	
    /*biz end*/
})

//查询按钮
$('#{$RDA$}_btn_{template_table_EN}_query').click(function () {
	/*设置查询条件变量*/
    /*set query param begin*/
	
    /*set query param end*/
	{$RDA$}_{template_table_EN}_query();
})

//vue回调
function {$RDA$}_{template_table_EN}_call_vue(objResult){
	//选择某条记录或自动选择第一条
	if ({$RDA$}_select_{template_table_EN}_rowId != "") 
		{$RDA$}_rowCheckData = $("#{$RDA$}_{template_table_EN}_Events").bootstrapTable('getData')[{$RDA$}_select_{template_table_EN}_rowId];
	
	if(index_subhtml == "{template_table_EN}_$.vue")
	{
		var n = Get_RandomDiv("{$RBC$}",objResult);	
		layer.open({
			type: 1,
	        area: ['1100px', '600px'],
	        fixed: false, //不固定
	        maxmin: true,
	        content: $(n),
	        success: function(layero, index){
	        	{$RDA$}_toparam = {};
	        	{$RDA$}_toparam["type"] = {$RDA$}_type;
	        	{$RDA$}_toparam["ly_index"] = index;
				if({$RDA$}_param.hasOwnProperty("hidden_find")){
					{$RDA$}_toparam["hidden_find"] = "1";
				}			
				/*查询条件参数传递至子页面,初次加载*/
				/*Send One FindSelect param bgein*/
					
				/*Send One FindSelect param end*/
				
	        	loadScript_hasparam("{$FFD$}/{template_table_EN}_$.js","{$RBC$}_{template_table_EN}_biz_start",{$RDA$}_toparam);
	        },
			end: function(){
				$(n).hide();
			}
	    });
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
	
	/*tab页显示子页面*/
	/*get tab subvue begin*/

	/*get tab subvue end*/
	
	//判断是否button按钮点击事件
	if({$RDA$}_prev_btn != {$RDA$}_btn){
		{$RDA$}_prev_btn = {$RDA$}_btn;
		if($("#"+{$RDA$}_btn)[0] == undefined)
			eval({$RDA$}_btn + "()");
		else
			$("#"+{$RDA$}_btn).click();
	}
}

//弹窗1
function {$RDA$}_open_to_url1(temindex_subhtml,temrandom_subhtml,temparam){
	{$RDA$}_btn = "";
	{$RDA$}_prev_btn = "";
	index_subhtml = s_decode(temindex_subhtml);
	inputrandom = s_decode(temrandom_subhtml);
	//本页面传到其他页面参数
	{$RDA$}_toparam = JSON.parse(s_decode(temparam));
	if(loadHtmlSubVueFun(index_subhtml,"{$RDA$}_{template_table_EN}_call_vue") == true){
		var n = Get_RandomDiv(inputrandom,"");
		layer.open({
			type: 1,
			area: ['1100px', '600px'],
			fixed: false, //不固定
			maxmin: true,
			content: $(n),
			success: function(layero, index){
				{$RDA$}_toparam["ly_index"] = index;
				eval(inputrandom+"_param = {}");
				for(var key in {$RDA$}_toparam)
					eval(inputrandom+"_param['"+key+"'] = '"+{$RDA$}_toparam[key]+"'");
				//参数传递并赋值
				eval(inputrandom+"_param_set()");
				var tbName = "";
				if(index_subhtml.indexOf("/") == -1)
					tbName = index_subhtml.substring(0,index_subhtml.indexOf(".vue"));
				else
					tbName = index_subhtml.substring(index_subhtml.lastIndexOf("/")+1,index_subhtml.indexOf(".vue"));
				eval(inputrandom+"_init_"+tbName+"()");
			},
			end: function(){
				$(n).hide();
			}
		});	
	}
}

//2:系统内tab页
function {$RDA$}_open_to_url2(temindex_subhtml,temrandom_subhtml,temparam,temtitle){
	{$RDA$}_btn = "";
	{$RDA$}_prev_btn = "";
	index_subhtml = s_decode(temindex_subhtml);
	inputrandom = s_decode(temrandom_subhtml);
	//调用或加载左侧菜单并click
	Add_No_Show_Menu(index_subhtml,inputrandom,JSON.parse(s_decode(temparam)),temtitle);	
}

//3：浏览器tab页
function {$RDA$}_open_to_url3(temindex_subhtml,temrandom_subhtml,temparam){
	{$RDA$}_btn = "";
	{$RDA$}_prev_btn = "";
	index_subhtml = s_decode(temindex_subhtml);
	inputrandom = s_decode(temrandom_subhtml);
	
	var temsrcparam = JSON.parse(s_decode(temparam));
	var vparam = "";	
	//单行选择
	var rowData = $("#{$RDA$}_{template_table_EN}_Events").bootstrapTable('getData')[{$RDA$}_select_{template_table_EN}_rowId];
	//多行选择
	var rowDatas = {$RDA$}_sel_row_{template_table_EN}();
	if(rowDatas.length > 0){
		$.each(rowDatas, function (i, obj) {
			for(var i = 0; i < temsrcparam.length; i ++){
				if(i != 0)
					vparam += "&"+temsrcparam[i]["TARGET_NAME"]+"="+obj[temsrcparam[i]["SOUR_NAME"]];
				else
					vparam = temsrcparam[i]["TARGET_NAME"]+"="+obj[temsrcparam[i]["SOUR_NAME"]];
			}
		});
	}
	else if(rowData != null){
		for(var i = 0; i < temsrcparam.length; i ++){
			if(i != 0)
				vparam += "&"+temsrcparam[i]["TARGET_NAME"]+"="+rowData[temsrcparam[i]["SOUR_NAME"]];
			else
				vparam = temsrcparam[i]["TARGET_NAME"]+"="+rowData[temsrcparam[i]["SOUR_NAME"]];
		}
	}
	window.open(index_subhtml+"?"+vparam,"_blank");
}

//按钮事件触发页面跳转，1:弹窗、2:系统内tab页、3：浏览器tab页
/*open new page begin*/

/*open new page end*/

//打开新页面
function {$RDA$}_open_url(objTag,iIndex){
	//弹窗
	if(iIndex == 0)
		{$RDA$}_open_to_url1($(objTag).attr("param1"),$(objTag).attr("param2"),$(objTag).attr("param3"));
	//系统内tab页
	else if(iIndex == 1)
		{$RDA$}_open_to_url2($(objTag).attr("param1"),$(objTag).attr("param2"),$(objTag).attr("param3"),$(objTag).attr("param4"));
	//浏览器tab页
	else if(iIndex == 2)
		{$RDA$}_open_to_url3($(objTag).attr("param1"),$(objTag).attr("param2"),$(objTag).attr("param3"));
}

//主从表选项卡动态添加
function {$RDA$}_adjust_tab(){
	if(typeof($("#{$RDA$}_TAB_MAIN")[0]) != "undefined" && $("#{$RDA$}_TAB_MAIN")[0].length != 0){
		{$RDA$}_Tab_Flag = 1;
		$(Get_RDivNoBuild("{$RDA$}","")).find(".wrapper-content").css("padding","20px 20px 0px 20px");
		$(Get_RDivNoBuild("{$RDA$}","")).find(".ibox").css("margin-bottom","0px");
		$(Get_RDivNoBuild("{$RDA$}","")).find(".ibox-content").css("padding","15px 20px 0px");		
		$($("#{$RDA$}_TAB_MAIN").find(".active")[0]).click();
	}
}

/*tab选项卡按钮点击事件*/
/*Tab Click Fun Begin*/

/*Tab Click Fun End*/

function {$RDA$}_show_tab_fun(inputUrl,inputrandom,temPar){
	index_subhtml = inputUrl;
	random_subhtml = inputrandom;
	if(loadHtmlSubVueFun("{$FFD$}/"+inputUrl,"{$RDA$}_{template_table_EN}_call_vue") == true){
		var n = Get_RandomDiv(inputrandom,"");
		$(n).show();
		var rowData = null;
		//选择某条记录或自动选择第一条并传递参数
		if ({$RDA$}_select_{template_table_EN}_rowId != "") 
			rowData = $("#{$RDA$}_{template_table_EN}_Events").bootstrapTable('getData')[{$RDA$}_select_{template_table_EN}_rowId];
		else
			rowData = {$RDA$}_rowCheckData;
		//$("#{$RDA$}_{template_table_EN}_Events").bootstrapTable('getData')[0];
		eval(inputrandom+"_param = {}");
		if(rowData != null){
			var temFlag = true;
			$.each(temPar, function (i, obj) {
				if(eval(inputrandom+"_param.hasOwnProperty(\""+obj.target_id+"\")") && eval(inputrandom+"_param[\""+obj.target_id+"\"]").toString() == rowData[obj.sourc_id].toString())
					temFlag = false;
				else
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \""+rowData[obj.sourc_id]+"\"");
			});
			if(temFlag){
				//传递子页面隐藏find功能
				eval(inputrandom+"_param[\"hidden_find\"] = \"1\"");
				//参数传递并赋值
				eval(inputrandom+"_param_set()");
				var tbName = inputUrl.substring(0,inputUrl.indexOf(".vue"));		
//				$("#"+inputrandom+"_btn_"+tbName+"_query").click();
				eval(inputrandom+"_"+tbName+"_biz_start("+inputrandom+"_param)");
			}
		}
		else{
			$.each(temPar, function (i, obj) {
				if(obj.sourc_id.toUpperCase() == "MAIN_ID")
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \"-999\"");
				else
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \"\"");
				return;
			});
			//传递子页面隐藏find功能
			eval(inputrandom+"_param[\"hidden_find\"] = \"1\"");
			//参数传递并赋值
			eval(inputrandom+"_param_set()");
			var tbName = inputUrl.substring(0,inputUrl.indexOf(".vue"));		
//			$("#"+inputrandom+"_btn_"+tbName+"_query").click();		
			eval(inputrandom+"_"+tbName+"_biz_start("+inputrandom+"_param)");
		}
	}
	//判断是否button按钮点击事件
	if({$RDA$}_prev_btn != {$RDA$}_btn){
		{$RDA$}_prev_btn = {$RDA$}_btn;
		$("#"+{$RDA$}_btn).click();
	}
}

//清除 查找框
function {$RDA$}_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//选择多行数据进行业务操作
function {$RDA$}_sel_row_{template_table_EN}(){
	//获得选中行
	var checkedbox= $("#{$RDA$}_{template_table_EN}_Events").bootstrapTable('getSelections'); 
	//将选中行数据转成jsonStr
	var jsonStr=JSON.stringify(checkedbox);
	//将jsonStr转成jsonObject对象	 
	var jsonObject=jQuery.parseJSON(jsonStr);
	return jsonObject;
	//接着就可以遍历jsonObject数组对象，取出并操作数据
	//alert(jsonObject);
}
